
/*

Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
using System;using BusinessLayer;using InfoClasses;using dpatoolkit.UILayer;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using DesignPatternDefinitions;
namespace dpatoolkit.UILayer
{
	/// <summary>
	/// Represents the UI for a Inheritance relation
	/// </summary>
	public class UIInheritance : IUIRelation
	{
		
		#region Fields
		private static  Pen capPen ,  nocapPen;
		#endregion

		#region Constructor
		
		static UIInheritance()
		{
            capPen = new Pen(UIRenderer.InheritanceColor, UIRenderer.RelationPenSize);
			capPen.CustomStartCap=PenCapProvider.GetInheritanceRepresentation();
            nocapPen = new Pen(UIRenderer.InheritanceColor, UIRenderer.RelationPenSize);
		}
		
		public UIInheritance(IUIObject _o1, IUIObject _o2,IDesignPatternSubject sub):
		base (String.Empty, _o1,_o2,null)
		{
			
			this.subject = sub;
			this.relationContextMenu.MenuItems[delIndex].Click+=new EventHandler(UIInheritanceDel_Click);
			this.relationContextMenu.MenuItems[revIndex].Click+=new EventHandler(UIInheritanceReverse_Click);
			MenuItem editItem = this.relationContextMenu.MenuItems[editIndex];
			this.relationContextMenu.MenuItems.Remove(editItem);

            this.relationType = RelationType.Inheritance;
		}	
		#endregion

		#region IUIRelation Members

		
		public  override void Draw(Graphics g)
		{
			//base.Draw(g,,,nocapPen)
			if( numPoints==3)
			{
				if(!recurs)
				{
					g.DrawLine(nocapPen,this.points3[0],this.points3[1]);
					g.DrawLine(capPen,this.points3[1],this.points3[2]);
					return;
				}
				g.DrawLine(capPen,this.points3[1],this.points3[0]);
				g.DrawLine(nocapPen,this.points3[2],this.points3[1]);
				return;
			}
			
			if(!recurs)
			{
				g.DrawLine(nocapPen,this.points4[0],this.points4[1]);
				g.DrawLine(nocapPen,this.points4[1],this.points4[2]);
				g.DrawLine(capPen,this.points4[2],this.points4[3]);
				return;
			}
			g.DrawLine(capPen,this.points4[1],this.points4[0]);
			g.DrawLine(nocapPen,this.points4[1],this.points4[2]);
			g.DrawLine(nocapPen,this.points4[3],this.points4[2]);
			return;
			
			
	
		}

		public  override void SetPariticapants(Rectangle r1, Rectangle r2)
		{
			
		}

		public override ContextMenu ContextMenu
		{
			get
			{
				return this.relationContextMenu;
			}
			set
			{
				//not implemented :P :-P
			}
		}

		#endregion


		private void UIInheritanceDel_Click(object sender, EventArgs e)
		{
			IInheritance inh = new InheritanceInfo();
			this.UnRegisterObserver();
			inh.DerivedClass = this.obj1.UIName;
			inh.DerivedClassComponent = this.obj1.UIComponent;
			inh.BaseClass = this.obj2.UIName;
			inh.BaseClassComponent = this.obj2.UIComponent;
			if(!this.subject.RemoveInheritance(inh))
				ErrorMessage.Show("Couldnt delete the inheritance");
		}

		private void UIInheritanceReverse_Click(object sender, EventArgs e)
		{
			IInheritance inh = new InheritanceInfo();
			inh.DerivedClass = this.obj1.UIName;
			inh.DerivedClassComponent = this.obj1.UIComponent;
			inh.BaseClass = this.obj2.UIName;
			inh.BaseClassComponent = this.obj2.UIComponent;
			if(!this.subject.RemoveInheritance(inh))
				ErrorMessage.Show("Couldnt reverse the inheritance(rem failed)");
			inh.DerivedClass = this.obj2.UIName;
			inh.DerivedClassComponent = this.obj2.UIComponent;
			inh.BaseClass = this.obj1.UIName;
			inh.BaseClassComponent = this.obj1.UIComponent;
			if(!this.subject.AddInheritance(inh,true))
				ErrorMessage.Show("Couldnt reverse the inheritance(add failed)");
				
		}
	}
}
